function AddTab()
{
if (_iTabs < _iMaxTabs)
{
var oArgs = new Object();
oArgs.Tab		= new TabObj("", null);
oArgs.FormXml	= oFormXml;

var oTab = openStdDlg(prependOrgName("/Tools/FormEditor/Dialogs/tab.aspx?title=" + encodeURI(LOCID_FORMED_ADDTAB) + "&description=" + encodeURI(LOCID_FORMED_ADDTABDESC)), oArgs, 350, 225, true);
if (oTab && AddTabXml(oTab))
{
AddTabHtml(oTab);
_iTabs++;
_iNexttabid++;
tabs.lastChild.click();
tabs.recalculateSize();
}
}
else
{
alert(LOCID_FORMED_MAXNUMBERTABS);
}
}
function UpdateTab(oActive)
{
var sTabName		= oActive.name;
var oTab = GetTabNode(sTabName);
var oLabels			= GetLocalizedObjsArray(oTab.selectNodes("labels/label"));
var bLockTab	= (oTab.getAttribute("locklevel") == "1");
var oTab = new TabObj(sTabName, oLabels,bLockTab);
var oArgs = new Object();
oArgs.Tab		= oTab;
oArgs.FormXml	= oFormXml;
var oUpdatedTab = openStdDlg(prependOrgName("/Tools/FormEditor/Dialogs/tab.aspx?title=" + encodeURI(LOCID_FORMED_TABPROPS) + "&description=" + encodeURI(LOCID_FORMED_MODIFYTABPROPS)), oArgs, 350, 225, true);
if (oUpdatedTab)
{
if (GetDescByLangCode(oTab.Labels) != GetDescByLangCode(oUpdatedTab.Labels) || oTab.LockTab != oUpdatedTab.LockTab)
{
UpdateTabXml(oTab, oUpdatedTab);
UpdateTabHtml(oActive, oUpdatedTab);
tabs.recalculateSize();
tabs.CurrentTab.click();
}
}
}
function AddTabXml(oTabObj)
{
if (oTabObj.TabName == null || oTabObj.TabName.length == 0)
{
return false;
}
var oTabs = oFormXml.selectSingleNode("/entity/form/tabs");
var oTab = oFormXml.createElement("tab");
oTab.setAttribute("name", oTabObj.TabName);
oTab.setAttribute("id", oTabObj.TabName);
oTab.setAttribute("IsUserDefined", "1");
oTab.setAttribute("locklevel", oTabObj.LockTab == true ? "1" : "0");
oTab.appendChild(oFormXml.createElement("labels"));
oTab.appendChild(oFormXml.createElement("sections"));
oTabs.appendChild(oTab);
PersistLocalizedNodes(oFormXml, "/entity/form/tabs/tab[@name = '" + oTabObj.TabName + "']/labels/label", oTabObj.Labels);
return true;
}
function UpdateTabXml(oTabObj, oUpdatedTabObj)
{
var oTab = GetTabNode(oTabObj.TabName);
oTab.setAttribute("name", oUpdatedTabObj.TabName);
oTab.setAttribute("locklevel", oUpdatedTabObj.LockTab == true ? "1" : "0");
PersistLocalizedNodes(oFormXml, "/entity/form/tabs/tab[@name = '" + oUpdatedTabObj.TabName + "']/labels/label", oUpdatedTabObj.Labels);
}
function AddTabHtml(oTabObj)
{
tabs.lastChild.insertAdjacentHTML("afterEnd", "<li class='ms-crm-Tab' tabid='tab" + _iNexttabid + "' id='tab_" + _iNexttabid + "' name='" + CrmEncodeDecode.CrmHtmlAttributeEncode(oTabObj.TabName) + "' onclick='SetActiveObject();' ondblclick='ViewPropertiesNow();'>" +
(oTabObj.LockTab == true ? "<img alt='" + LOCID_FORMEDITOR_TAB_LOCKED + "' class='imgLock' src='/_imgs/tools/ico_lock.gif' />" : "") +
"<a onclick='return false;' href='javascript:onclick();' target='_self' class='ms-crm-Tab'>" + CrmEncodeDecode.CrmHtmlEncode(GetDescByLangCode(oTabObj.Labels)) + "</a>" +
"</li>");
tabContent.lastChild.insertAdjacentHTML("afterEnd", "<div class='ms-crm-Tab' id='tab" + _iNexttabid + "'><table cellspacing='0' cellpadding='0' class='stdTable'><tr><td></td></tr></table></div>");
}
function UpdateTabHtml(oActive, oUpdatedTabObj)
{
oActive.name		= oUpdatedTabObj.TabName;
oActive.innerHTML = (oUpdatedTabObj.LockTab == true ? "<img alt='" + LOCID_FORMEDITOR_TAB_LOCKED + "' class='imgLock' src='/_imgs/tools/ico_lock.gif' />" : "");
oActive.innerHTML += CrmEncodeDecode.CrmHtmlEncode(GetDescByLangCode(oUpdatedTabObj.Labels));
}
function RemoveTab(oActive)
{
if (_iTabs > 1)
{
var oTab = oFormXml.selectSingleNode("/entity/form/tabs/tab[@name = '" + GetCurrentTabName(oActive) + "']");
if (oTab.getAttribute("locklevel") == "1")
{

alert(LOCID_FORMED_REMOVETABLOCKED);
return false;
}
if (oTab.selectSingleNode("sections/section[@locklevel and @locklevel != '0']"))
{

alert(LOCID_FORMED_REMOVETABLOCKEDSEC);
return false;
}
var oNodes = oTab.selectNodes("sections/section/rows/row/cell/control");
if (!IsRemovable(oNodes))
{
alert(LOCID_FORMED_REMOVETABLOCKEDFLD);
return false;
}
var sfieldList = GetDependentList(oNodes, true);
if (sfieldList.length > 0)
{

alert(LOCID_FORMED_TABFLDDEPENDENTTITL + "\n\n" + LOCID_FORMED_TABFLDDEPENDENTHEAD + "\n\n" + sfieldList + "\n\n" + LOCID_FORMED_TABFLDDEPENDENTFOOT);
return false;
}
RemoveTabXml(oActive);
RemoveTabHtml(oActive);
_iTabs--;
return true;
}
else
{
alert(LOCID_FORMED_ATLEASTONETAB);
return false;
}
}
function RemoveTabXml(oActive)
{
var oTab = GetTabNode(oActive.name);
oTab.parentNode.removeChild(oTab);
}
function RemoveTabHtml(oActive)
{
if (!oActive.previousSibling)
{
oActive.nextSibling.click();
}
else
{
tabs.firstChild.click();
}
oTab = window.document.all(oActive.tabid);
oTab.parentElement.removeChild(oTab);
oActive.parentElement.removeChild(oActive);
}
